<?php

require_once($INCLUDE_PATH.'app/controller/InitController.php');
require_once ($INCLUDE_PATH . "/inc/checkfun.php");
require_once ($INCLUDE_PATH . "/include/WebService2Db.php");
function __autoload($class_name) {
    require_once APP_ROOT.'app/model/'.strtolower($class_name) . '.php';
}
class UserController extends InitController {

    public function __construct() {
        parent::__construct();

    }


    public function actionAdd() {
        if ($_REQUEST['a']) {
            $s = array();

            $s['account'] = $_REQUEST['account'];
            $s['user_type'] = $_REQUEST['user_type'];
            $s['state']=$_REQUEST['state'];
            $s['email']=$_REQUEST['email'];
            $s['password']=md5($_REQUEST['password']);
            $s['company']=$_REQUEST['company'];
            $s['name']=$_REQUEST['name'];
            $s['gender']=$_REQUEST['gender'];
            $s['mobile']=$_REQUEST['mobile'];
            $s['tel']=$_REQUEST['tel'];
            $s['email']=$_REQUEST['email'];
            $s['address']=$_REQUEST['address'];
            $s['zip']=$_REQUEST['zip'];
            $s['opentime']=$_REQUEST['opentime'];
            $s['closetime']=$_REQUEST['closetime'];
            if ($_REQUEST["id"]) {

            }else {
                $s['id'] = "null";
                $result = UserModel::saveUserInfo($s);
                if ($result) {
                    return self::sysMessage("添加新用户成功！", array("返回上一页" => "javascript:history.go(-1);", "关闭窗口" => "javascript:window.close();"));
                }else{
                    return self::sysMessage("添加新用户失败！", array("返回上一页" => "javascript:history.go(-1);", "关闭窗口" => "javascript:window.close();"));
                }
            }
        }

    //echo PRE.'hhj';
    }
    public function actionList()
    {
      if($_REQUEST['p'])
      {
          $page = $_REQUEST['p'];
      }else{
       $page = 1;
      }
      $pageSize = 20;
       $sum = UserModel::getListCount();
        if (ceil ( $sum / $pageSize ) <= $page)
       {
           $page = ceil ( $sum / $pageSize );
       }
        $liststart=$pageSize * ($page - 1);
       $result = UserModel::getList($page,$liststart,$pageSize);
       Y::$tpl->set("list",$result);
    }





}

?>
